﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

using VipCo.Data;
using VipCo.Entities;

public partial class Admin_LienHe_HTLienHe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Context.User.Identity.IsAuthenticated)
        {
            FormsAuthentication.RedirectToLoginPage();
        }
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["id"] != null)
            {
                try
                {
                    H_CatalogId.Value = Request.QueryString["id"].ToString();
                    LienHe entLienHe = DataRepository.LienHeProvider.GetById(new Guid(H_CatalogId.Value));
                    if (entLienHe != null)
                    {
                        txtHoTen.Text = entLienHe.HoTen;
                        txtThuDienTu.Text = entLienHe.ThuDienTu;
                        txtNoiDung.Text = Server.HtmlDecode(entLienHe.NoiDung);
                        txtPhone.Text = entLienHe.DienThoai;
                    }
                }
                catch (Exception ex)
                {
                    Common.WriteLog("HTLienHe.aspx.cs", "Page_Load()", ex.ToString());
                    string strScript = "<script>parent.parent.GB_hide();</script>";
                    this.RegisterClientScriptBlock("strScript", strScript);
                }
            }
        }
    }

    protected void cmdDelete_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            bool updateStatus = DataRepository.LienHeProvider.Delete(new Guid(H_CatalogId.Value));
            if (updateStatus)
                WebMessage.Show("Xóa Liên hệ thành công!");
            else
                WebMessage.Show("Xóa Liên hệ thất bại!");

            string strScript = "<script>parent.parent.GB_hide();</script>";
            this.RegisterClientScriptBlock("strScript", strScript);
        }
        catch (Exception ex)
        {
            Common.WriteLog("HTLienHe.aspx.cs", "cmdDelete_Click()", ex.ToString());
            WebMessage.Show("Xóa Liên hệ thất bại!");
        }
    }
}
